/*
 * @PageName: 
 * @Description: 
 * @FilePath: /glm-mes-pc/src/utils/useOpenBPM.js
 */
import { getBPMAccessToken, getBPMEcoOauth2Token } from '@/api/office'
import useUserStore from '@/store/modules/user'
import { ElMessage } from 'element-plus'
const userStore = useUserStore()
const bpmUrl = import.meta.env.VITE_BPM_SERVE
export async function getBpmEcoOauth2Token() {
	try {
		// 获取应用注册授权令牌eco-oauth2-token，用于调用bpm接口使用
		const res = await getBPMEcoOauth2Token({
			url: bpmUrl,
			userId: userStore.name
		})
		return res
	} catch (error) {
		console.log('error===>', error)
		ElMessage.error(error)
	}
}
export async function  useOpenBPM(url) {
  
  // 获取BPM access-token用于跳转到bpmn的页面
	try {
		const res = await getBPMAccessToken({
			url: bpmUrl,
			userId: userStore.name
		})
		// 跳转到BPM页面
		window.open(bpmUrl + `/api/static-page/login-sso/builtin/default.html?auth-code=${res.data}&target=${url}`)
	} catch (error) {
		this.$modal.msgError(error)
	}
}